package com.example.springcloudwinter.mapper;

import com.example.springcloudwinter.po.UserPo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.sql.SQLException;

@Mapper
public interface UserMapper {

    @Select("SELECT count(*) FROM user WHERE userId=#{userId} AND password=#{password}")
    int login(@Param("userId")String userId, @Param("password")String password);

    @Select("SELECT count(*) FROM user WHERE userId=#{userId}")
    int isUserIdExisted(@Param("userId")String userId);

    @Insert("INSERT INTO user (`userId`,`password`, `userName`, `userSex`) VALUES(#{userId},#{password},#{nickname},#{sex})")
    void insertUser(@Param("userId")String userId,@Param("password")String password,
                    @Param("nickname")String nickname,@Param("sex")int sex);

    @Select("SELECT userId,userName,userSex,userImg,delTag FROM user WHERE user.userId=#{userId}")
    UserPo getUserById(@RequestParam("userId")String userId)throws SQLException;
}
